<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/*
			1! = 1 * 1;
			2! = 1 * 2;
			3! = 1 * 2 * 3;
			4! = 1 * 2 * 3 * 4;
			*/
			//5. 让用户输出一个整数n, 求 1!+2!+3!+4!+…n!。
			var n = window.prompt("请输入一个整数：");
			var sum = 1;
			var sum2 = 0;
			for (i = 1; i <= n; i++) {
				sum *= i;//从1开始乘，乘到用户输入的数为止
				sum2 += sum;
				/*
				n = 4;
				i = 1	sum = 1 * 1 = 1		sum2 = 0 + 1 =1
				i = 2	sum = 1 * 2 = 2		sum2 = 2 + 1 =3
				i = 3	sum = 2 * 3 = 6		sum2 = 3 + 6 =8
				i = 4	sum = 6 * 4 = 24	sum2 = 8 + 24 =33
				所以1到4的阶乘相加为33
				*/
				
			}document.write(sum2); 
		</script>
	</body>
</html>
